package MyFront.Controller;

import MyFramePro.Constants.SystemConstants;
import MyFramePro.Domain.Dto.CommentDTO;
import MyFramePro.Domain.Entity.Comment;
import MyFramePro.Domain.ResponseResult;
import MyFramePro.Service.Impl.CommentServiceImpl;
import MyFramePro.Utils.BeanCopyUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping(value = "/comment")
public class CommentController {

    @Resource
    private CommentServiceImpl commentService;

    /**
     * 查询非友链评论的功能
     * @param articleId 文章 ID
     * @param pageNum   当前页数
     * @param pageSize  每页中的记录数
     */
    @GetMapping(value = "/commentList")
    public ResponseResult commentList(Long articleId,Integer pageNum,Integer pageSize){

        return commentService.commentList(SystemConstants.ARTICLE_COMMENT,articleId,pageNum,pageSize);
    }


    /**
     * 这里是友链发表评论的功能
     */
    @GetMapping(value = "/linkCommentList")
    public ResponseResult linkCommentList(Integer pageNum,Integer pageSize){

        return commentService.commentList(SystemConstants.LINK_COMMENT,null,pageNum,pageSize);
    }


    /**
     * 这里是发表评论的功能
     */
    @PostMapping
    public ResponseResult sendComment(@RequestBody CommentDTO commentDTO){

        Comment comment = BeanCopyUtils.myCopyBean(commentDTO, Comment.class);
        return commentService.sendComment(comment);
    }

}
